#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START dracut-native
# depends: kmod-native
# depends: xz-native

save_CFLAGS="$CFLAGS"
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
export CFLAGS='-O2 -g'
export CPPFLAGS="-I${xtools}${build_prefix}/include"
export LDFLAGS="-L${xtools}${build_prefix}/lib"
export PKG_CONFIG_LIBDIR="${xtools}${build_prefix}/lib/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="${xtools}${build_prefix}"


rm -rf build/dracut-native
cp -a dracut build/dracut-native
cd build/dracut-native
# Thanks God dracut does NOT use autocrap
env \
	CC="gcc" \
	KMOD_CFLAGS="-I${xtools}${build_prefix}/include" \
	KMOD_LIBS="-L${xtools}${build_prefix}/lib -lkmod -llzma" \
	PKG_CONFIG_LIBDIR="${xtools}${build_prefix}/lib/pkgconfig" \
./configure \
	--prefix="$build_prefix" \
	--disable-documentation \
	--systemdsystemunitdir=$build_prefix/lib/systemd/system \
	${NIL}

env \
	CC="gcc" \
	KMOD_CFLAGS="-I${xtools}${build_prefix}/include" \
	KMOD_LIBS="-L${xtools}${build_prefix}/lib -lkmod -llzma" \
	PKG_CONFIG_LIBDIR="${xtools}${build_prefix}/lib/pkgconfig" \
make -j${JOBS} \
	all \
	install \
	DESTDIR="$xtools"

cd ../..
rm -rf build/dracut-native

export CFLAGS="$save_CFLAGS"
export CPPFLAGS="$save_CPPFLAGS"
export LDFLAGS="$save_LDFLAGS"
unset PKG_CONFIG_LIBDIR
unset PKG_CONFIG_SYSROOT_DIR

# RECIPE END dracut-native
